Implement '-vs' status display for Garmin and Magellan on waypoint download
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 24 Jul 2004 19:51:22 +0000 (19:51 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 24 Jul 2004 19:51:22 +0000 (19:51 +0000)
from the unit.

gpsbabel/garmin.c
gpsbabel/jeeps/gpsapp.c
gpsbabel/jeeps/gpsapp.h
gpsbabel/jeeps/gpscom.c
gpsbabel/jeeps/gpscom.h
gpsbabel/magproto.c
gpsbabel/waypt.c

index 075c8e9a2ebaef7dbce5b115a5de49bfbef7d5a8..d3cd6cd3de1fef1cd6490f6c21f34b64a9aa790c 100644 (file)
@@ -148,6 +148,17 @@ rw_deinit(void)
        }
 }
 
+static int
+waypt_read_cb(int total_ct, GPS_PWay *way)
+{
+       static int i;
+
+       if (global_opts.verbose_status) {
+               i++;
+               waypt_status_disp(total_ct, i);
+       }
+}
+
 static void
 waypt_read(void)
 {
@@ -163,7 +174,7 @@ waypt_read(void)
                return;
        }
 
-       if ((n = GPS_Command_Get_Waypoint(portname, &way)) < 0) {
+       if ((n = GPS_Command_Get_Waypoint(portname, &way, waypt_read_cb)) < 0) {
                fatal(MYNAME  ":Can't get waypoint from %s\n", portname);
        }
 
@@ -371,6 +382,7 @@ sane_GPS_Way_New(void)
 
        return way;
 }
+
 static int 
 waypt_write_cb(GPS_PWay *way)
 {
@@ -379,8 +391,7 @@ waypt_write_cb(GPS_PWay *way)
 
        if (global_opts.verbose_status) {
                i++;
-               fprintf(stdout, "%d/%d/%d\r", i*100/n, i, n);
-               fflush(stdout);
+               waypt_status_disp(n, i);
        }
        return 0;
 }
index 6c30003eaf1c3dee89c53bac90d9f41b16ea7b1e..5f8617a9335f8702b943e2e48bfc2eff465ddeea 100644 (file)
@@ -574,7 +574,7 @@ static void GPS_A001(GPS_PPacket packet)
 **
 ** @return [int32] number of waypoint entries
 ************************************************************************/
-int32 GPS_A100_Get(const char *port, GPS_PWay **way)
+int32 GPS_A100_Get(const char *port, GPS_PWay **way, int (*cb)())
 {
     static UC data[2];
     int32 fd;
@@ -628,7 +628,6 @@ int32 GPS_A100_Get(const char *port, GPS_PWay **way)
            return gps_errno;
        if(!GPS_Send_Ack(fd, &tra, &rec))
            return gps_errno;
-
        switch(gps_waypt_type)
        {
        case pD100:
@@ -680,6 +679,10 @@ int32 GPS_A100_Get(const char *port, GPS_PWay **way)
            GPS_Error("A100_GET: Unknown waypoint protocol");
            return PROTOCOL_ERROR;
        }
+       /* Issue callback for status updates. */
+       if (cb) {
+               cb(n, &((*way)[i]));
+       }
     }
 
     if(!GPS_Packet_Read(fd, &rec))
index 5f27450a39a27d02fa5b3c20097a651573baf9d9..1ceecaef59dd449879b3dcdd6f6b167564786176 100644 (file)
@@ -11,7 +11,7 @@ extern "C"
 
 int32  GPS_Init(const char *port);
 
-int32  GPS_A100_Get(const char *port, GPS_PWay **way);
+int32  GPS_A100_Get(const char *port, GPS_PWay **way, int (*cb)(int ct, GPS_PWay *));
 int32  GPS_A100_Send(const char *port, GPS_PWay *way, int32 n, int (*cb)(GPS_PWay *));
 
 int32  GPS_A200_Get(const char *port, GPS_PWay **way);
index 235a5c4ea4999aeec92c6ac1f6579fb6478e4625..1e45be28e66dec313016a255b8d044daad2c72f0 100644 (file)
@@ -82,14 +82,14 @@ int32 GPS_Command_Off(const char *port)
 ** @return [int32] number of waypoint entries
 ************************************************************************/
 
-int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way)
+int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way, int (*cb)())
 {
     int32 ret=0;
 
     switch(gps_waypt_transfer)
     {
     case pA100:
-       ret = GPS_A100_Get(port,way);
+       ret = GPS_A100_Get(port,way, cb);
        break;
     default:
        GPS_Error("Get_Waypoint: Unknown waypoint protocol");
index 90c0cba5218288987a8a6eb6389222ece3129771..0d84157367b2605a13afbe440e5aa42db56a00d4 100644 (file)
@@ -28,7 +28,7 @@ int32  GPS_Command_Send_Almanac(const char *port, GPS_PAlmanac *alm, int32 n);
 int32  GPS_Command_Get_Track(const char *port, GPS_PTrack **trk);
 int32  GPS_Command_Send_Track(const char *port, GPS_PTrack *trk, int32 n);
 
-int32  GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way);
+int32  GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way,int (*cb)());
 int32  GPS_Command_Send_Waypoint(const char *port, GPS_PWay *way, int32 n, int (*cb)());
 
 int32  GPS_Command_Get_Proximity(const char *port, GPS_PWay **way);
index 829fc104d63b1139d204373c7e6fc2c34aeec77f..646ee8d26d433704f7b3980e4b03302c04188747 100644 (file)
@@ -1,7 +1,7 @@
 /*
     Communicate Thales/Magellan serial protocol.
 
-    Copyright (C) 2002 Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002, 2003, 2004 Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -40,6 +40,7 @@ static char *deficon;
 static char *bs;
 static char *noack;
 static int route_out_count;
+static int waypoint_read_count;
 
 typedef enum {
        mrs_handoff = 0,
@@ -430,6 +431,8 @@ retry:
        } 
        if (strncmp(ibuf, "$PMGNWPT,", 7) == 0) {
                waypoint *wpt = mag_wptparse(ibuf);
+               waypoint_read_count++;
+               waypt_status_disp(waypoint_read_count, waypoint_read_count);
                switch (global_opts.objective)
                {
                        case wptdata:
@@ -715,6 +718,7 @@ static void
 mag_rd_init(const char *portname)
 {
        time_t now, later;
+       waypoint_read_count = 0;
 
        if (bs) {
                bitrate=atoi(bs);
index 7b6c7efd5959140cf763b1eff13f5548d36a9bd0..f5f2323a8310424160b9e42069b0d6e0b15f889f 100644 (file)
@@ -146,6 +146,13 @@ waypt_disp(const waypoint *wpt)
        printf("\n");
 }
 
+void
+waypt_status_disp(int total_ct, int myct)
+{
+       fprintf(stdout, "%d/%d/%d\r", myct*100/total_ct, myct, total_ct);
+       fflush(stdout);
+}
+
 void
 waypt_disp_all(waypt_cb cb)
 {
@@ -157,8 +164,7 @@ waypt_disp_all(waypt_cb cb)
                waypointp = (waypoint *) elem;
                if (global_opts.verbose_status) {
                        i++;
-                       fprintf(stdout, "%d/%d/%d\r", i*100/waypt_ct, i, waypt_ct);
-                       fflush(stdout);
+                       waypt_status_disp(waypt_ct, i);
                }
                (*cb) (waypointp);
        }